' Sample for SharpPlot.
' Compile using "vbc /r:Microsoft.VisualBasic.dll,System.Drawing.dll,SharpPlot.dll sample.vb"

Imports Microsoft.VisualBasic
Imports System
Imports System.Drawing
Imports System.Drawing.Imaging
Imports Causeway
 
Namespace SharpPlotSample
  Class Example
    Shared  Sub Main(ByVal args() As String)

     ' A simple composite chart showing most key features
     ' Overlays a linechart on a barchart and adds a small piechart in the corner
      Dim sp As SharpPlot =  New SharpPlot() 
	  
      sp.Heading = "Financial Summary for Current Year"
      sp.SetHeadingFont("Arial",18,FontStyle.Bold,Color.Firebrick)

      Dim data1() As Integer =  New Integer() {6,18,27,31,56,72,45,12}
      Dim data2() As Integer =  New Integer() {9,23,32,33,59,81,47,13}
      Dim xdata() As Integer =  New Integer() {126,128,129,130,131,135,137,18}
      Dim xlabs() As String  =  New String()  {"Jan","Feb","Mar","Apr","May","June","July","August"&chr(10)&"(part)"}

     ' Let's start with a nice graded paper
      sp.SetBackground(Color.Wheat,FillStyle.GradientBottomRight)
      sp.MarginTop = 56

     ' Check out a custom line-style for the datum line
      sp.SetDatumLineStyle(Color.Navy,New LineStyle(New Integer() {24,3,2,3,2,3}))
      sp.SetYDatumLines(40)

     ' Draw the base barchart
      sp.YCaption = "$M"
      sp.YAxisStyle = YAxisStyles.ForceZero Or YAxisStyles.AtEndCaption
      sp.SetXLabels(xlabs)
      sp.DrawBarChart(data1)

     ' Overlay a linegraph on the same axis set
      sp.LineGraphStyle = LineGraphStyles.Markers Or LineGraphStyles.Risers Or LineGraphStyles.Curves
      sp.SetLineStyles(LineStyle.Dash)
      sp.SetMarkers(Marker.Lozenge)
      sp.SetColors(New Color() {Color.DodgerBlue,Color.Firebrick,Color.Firebrick})
      sp.SetPenWidths(0.8) ' For line and risers
      sp.Flexibility = 5
      sp.DrawLineGraph(data2)

     ' Key picks up series info from both charts
      sp.SetKeyText(New String() {"Revenue","Invoiced Sales"})
      sp.KeyStyle = KeyStyles.Boxed Or KeyStyles.Rounded

     ' Add some free text in a box
      sp.NoteStyle = NoteStyles.Boxed Or NoteStyles.Rounded
      sp.SetNoteBackground(Color.Goldenrod)
      sp.SetNoteFont(Color.White)
      sp.DrawNote("Note: April figures were affected by warehouse fire",3.5,20,0,1.6)

     ' Finally, drop in a small pie (scaled to 50% and off-centre)
      sp.SetXLabelFont("Arial",13.4,FontStyle.Bold,Color.Navy)
      sp.SetXLabels(New String() {"Home","Export"})
      sp.SetPieCenter(100,180)
      sp.PieRadius = 50
      sp.SetEdgeStyle(Color.White,LineStyle.Solid,1.8)
      sp.DrawPieChart(New Integer(){34,23})

     ' Save the chart as an SVG image (in the current directory)
      Dim filename As String =  "sample" 
      sp.SaveSvg(filename + ".svg")

     ' Save the chart as a 96dpi PNG image
      sp.SaveImage(filename + ".png", ImageFormat.Png)
      Console.WriteLine("Saved " + filename + " as an SVG document, and a small PNG image")

    End Sub
  End Class
End Namespace